package com.briup.jz.service.impl;

import java.util.Date;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.briup.jz.bean.OrderComment;
import com.briup.jz.bean.OrderCommentExample;
import com.briup.jz.bean.extend.OrderCommentExtend;
import com.briup.jz.dao.OrderCommentMapper;
import com.briup.jz.dao.extend.OrderCommentExtendMapper;
import com.briup.jz.service.IOrderCommentService;

@Service
public class OrderCommentServiceImpl implements IOrderCommentService{

	@Autowired
	private OrderCommentMapper orderCommentMapper;
	@Autowired
	private OrderCommentExtendMapper orderCommentExtendMapper;
	
	@Override
	public void deleteById(Long id) {
		orderCommentMapper.deleteByPrimaryKey(id);
	}

	@Override
	public void changeStatus(Long id, String status) {
		OrderComment orderComment = orderCommentMapper.selectByPrimaryKey(id);
		orderComment.setStatus(status);
		orderCommentMapper.updateByPrimaryKey(orderComment);
	}

	@Override
	public void saveOrUpdate(OrderComment orderComment) {
		if(orderComment.getId()==null) {
			orderComment.setCommentTime(new Date().getTime());
			orderComment.setStatus("不通过");
			orderCommentMapper.insert(orderComment);
		} else {
			orderCommentMapper.updateByPrimaryKey(orderComment);
		}
	}


	@Override
	public List<OrderComment> findAll() {
		OrderCommentExample example = new OrderCommentExample();
		List<OrderComment> orderComments = orderCommentMapper.selectByExample(example);
		return orderComments;
	}

	@Override
	public List<OrderCommentExtend> pageQuery(int page, int pageSize, String content, String status, Long orderId) {
		int pageIndex = (page-1)*pageSize;
		List<OrderCommentExtend> orderCommentExtends = orderCommentExtendMapper.pageQuery(pageIndex, pageSize, content, status, orderId);
		return orderCommentExtends;
	}
	
}
